﻿Imports System.IO

Public Class Inicio
    Dim iniError As String = ""

    Public Sub New()
        Dim Parametros() As String = GetCommandLineArgs()

        If Parametros.Length > 0 And Parametros(0).Trim <> "" Then
            If Parametros(0) = "Config" Then
                Dim conf As New Config
                conf.StartPosition = FormStartPosition.CenterScreen
                conf.ShowDialog()
                End
            End If
        Else
            InitializeComponent()
        End If

        Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None

        iniError = Inicializa()

    End Sub

    Private Function GetCommandLineArgs() As String()
        Dim separators As String = " "
        Dim commands As String = Microsoft.VisualBasic.Command()
        Dim args() As String = commands.Split(separators.ToCharArray)
        Return args
    End Function

    Private Function Inicializa() As String
        dsConfig = New DataSet
        dsData = New DataSet
        dsInfo = New DataSet

        ruta_programa = Application.StartupPath

        msg.p_error.Image = Image.FromFile(ruta_programa & "\Images\Error.png")
        msg.p_exclamacion.Image = Image.FromFile(ruta_programa & "\Images\Exclamacion.png")
        msg.p_informacion.Image = Image.FromFile(ruta_programa & "\Images\Info.png")
        msg.p_pregunta.Image = Image.FromFile(ruta_programa & "\Images\Pregunta.png")

        Dim escala As Integer = 50
        lbSync.Image = Image.FromFile(ruta_programa & "\Images\Sync.png")
        Comprime_Imagen(lbSync.Image, CInt(lbPed.Width - escala), CInt(lbPed.Height - escala))
        lbSync.Tag = Image.FromFile(ruta_programa & "\Images\Sync.png")

        lbPed.Image = Image.FromFile(ruta_programa & "\Images\Pedido.png")
        Comprime_Imagen(lbPed.Image, CInt(lbSync.Width - escala), CInt(lbSync.Height - escala))
        lbPed.Tag = Image.FromFile(ruta_programa & "\Images\Pedido.png")

        lbRep.Image = Image.FromFile(ruta_programa & "\Images\Reportes.png")
        Comprime_Imagen(lbRep.Image, CInt(lbRep.Width - escala), CInt(lbRep.Height - escala))
        lbRep.Tag = Image.FromFile(ruta_programa & "\Images\Reportes.png")

        msg.Establece_textos("&Abortar", "&Reintentar", "&Ignorar", "&Aceptar", "&Cancelar", "&Si", "&No")


        If File.Exists(ruta_programa & "\Config.xml") Then
            dsConfig.ReadXml(ruta_programa & "\Config.xml")
        Else
            Return "No se encuentra el archivo de configuración" & vbCrLf & vbCrLf & "No se puede iniciar el sistema"
        End If

        Dim fondo As New Bitmap(Me.Width, Me.Height)
        Dim gf As Graphics = Graphics.FromImage(fondo)
        gf.DrawImage(Image.FromFile(ruta_programa & "\Images\Inicio.png"), 0, 0, fondo.Width, fondo.Height)
        gf.DrawImage(My.Resources.logo, fondo.Width - 90, fondo.Height - 70, 80, 60)
        Dim sf As New StringFormat
        sf.Alignment = StringAlignment.Far
        gf.DrawString(Valor_Config("EMPRESA", "Nombre"), New Font("Corbel", 22, FontStyle.Bold), Brushes.DimGray, fondo.Width - 100, fondo.Height - 45, sf)
        gf.DrawRectangle(Pens.DimGray, New Rectangle(0, 0, fondo.Width - 1, fondo.Height - 1))
        sf.Alignment = StringAlignment.Near
        gf.DrawString(Valor_Config("EMPRESA", "Nombre del vendedor"), New Font("Corbel", 11, FontStyle.Bold), Brushes.Silver, 5, 5, sf)
        Me.BackgroundImage = fondo

        Return ""
    End Function

    Private Sub Inicio_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not iniError = "" Then
            msg.Mostrar(iniError, "", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Me.Close()
        End If

        'msg.Mostrar("Mensajes", "", MessageBoxButtons.OK, MessageBoxIcon.Error)
    End Sub

    Private Sub pbCerrar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pbCerrar.Click
        Me.Close()
    End Sub

    Private Sub lb_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbRep.MouseEnter, lbPed.MouseEnter, lbSync.MouseEnter
        Dim escala As Integer = 20
        Dim bmp As Image = CType(sender, Label).Tag
        Comprime_Imagen(bmp, CType(sender, Label).Image.Width + escala, CType(sender, Label).Image.Height + escala)
        CType(sender, Label).Image = bmp
        CType(sender, Label).Font = New Font(CType(sender, Label).Font.Name, CType(sender, Label).Font.Size + 1, CType(sender, Label).Font.Style)
        CType(sender, Label).ForeColor = Color.DimGray
    End Sub

    Private Sub lb_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbPed.MouseLeave, lbRep.MouseLeave, lbSync.MouseLeave
        Dim escala As Integer = 20
        Dim bmp As Image = CType(sender, Label).Tag
        Comprime_Imagen(bmp, CType(sender, Label).Image.Width - escala, CType(sender, Label).Image.Height - escala)
        CType(sender, Label).Image = bmp
        CType(sender, Label).Font = New Font(CType(sender, Label).Font.Name, CType(sender, Label).Font.Size - 1, CType(sender, Label).Font.Style)
        CType(sender, Label).ForeColor = Color.Gray
    End Sub

    Private Sub lbSync_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbSync.Click
        Dim forma As New Syncronizar
        Me.Hide()
        forma.ShowDialog()
        forma.Dispose()
        Me.Show()
        Me.BringToFront()
    End Sub

    Private Sub lbPed_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbPed.Click
        'Dim forma As New Pedidos
        Dim forma As New Metas
        Me.Hide()
        forma.ShowDialog()
        forma.Dispose()
        Me.Show()
        Me.BringToFront()
    End Sub

    Private Sub lbRep_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbRep.Click
        Dim forma As New Reportes
        Me.Hide()
        forma.ShowDialog()
        forma.Dispose()
        Me.Show()
        Me.BringToFront()
    End Sub

    'Private Sub lbresumen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbresumen.Click
    '    Dim forma As New Resumen
    '    Me.Hide()
    '    forma.ShowDialog()
    '    forma.Dispose()
    '    Me.Show()
    '    Me.BringToFront()
    'End Sub
End Class